Completed
Push — master ( 8967bc...e88c19 )
by Rain
02:47
created

AbstracCheckbox.js ➔ ???   B

Complexity

Conditions 1

Size

Total Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
c 2
b 0
f 0
dl 0
loc 31
rs 8.8571
1
2
import ko from 'ko';
3
import {isUnd} from 'Common/Utils';
4
import {AbstractComponent} from 'Component/Abstract';
5
6
class AbstracCheckbox extends AbstractComponent
7
{
8
	/**
9
	 * @constructor
10
	 * @param {Object} params = {}
11
	 */
12
	constructor(params = {}) {
13
14
		super();
15
16
		this.value = params.value;
17
		if (isUnd(this.value) || !this.value.subscribe)
18
		{
19
			this.value = ko.observable(isUnd(this.value) ? false : !!this.value);
20
		}
21
22
		this.enable = params.enable;
23
		if (isUnd(this.enable) || !this.enable.subscribe)
24
		{
25
			this.enable = ko.observable(isUnd(this.enable) ? true : !!this.enable);
26
		}
27
28
		this.disable = params.disable;
29
		if (isUnd(this.disable) || !this.disable.subscribe)
30
		{
31
			this.disable = ko.observable(isUnd(this.disable) ? false : !!this.disable);
32
		}
33
34
		this.label = params.label || '';
35
		this.inline = isUnd(params.inline) ? false : params.inline;
36
37
		this.readOnly = isUnd(params.readOnly) ? false : !!params.readOnly;
38
		this.inverted = isUnd(params.inverted) ? false : !!params.inverted;
39
40
		this.labeled = !isUnd(params.label);
41
		this.labelAnimated = !!params.labelAnimated;
42
	}
43
44
	click() {
45
		if (!this.readOnly && this.enable() && !this.disable())
46
		{
47
			this.value(!this.value());
48
		}
49
	}
50
}
51
52
export {AbstracCheckbox, AbstracCheckbox as default};
53